﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using A2DFramework.InstanceService;
using A2DFramework.QueueService;

namespace A2DFramework.LogService.LogProviders
{
    public class QueueLogger : ILog
    {
        private IQueue queueSrv;
        public QueueLogger()
        {
            queueSrv = ObjectFactory.Resolve<IQueue>();
            queueSrv.CreateIfNotExists<ExceptionWrapper>();
        }

        public void Log(Exception ex, params string[] additionalInfos)
        {
            ExceptionWrapper wrapper = new ExceptionWrapper(ex);
            if (additionalInfos!=null)
                wrapper.AdditionalInfos = additionalInfos.ToList();

            queueSrv.SendRequest2Worker<ExceptionWrapper>(wrapper);
        }

        public void Log(string message, params string[] additionalInfos)
        {
            ExceptionWrapper wrapper = new ExceptionWrapper(new Exception(message));
            if (additionalInfos != null)
                wrapper.AdditionalInfos = additionalInfos.ToList();

            queueSrv.SendRequest2Worker<ExceptionWrapper>(wrapper);
        }
    }
}
